<template>
  <div class="send-message">
    <div v-if="userInfoData" class="has-loging">
      <div class="user-cover">
        <img :src="userInfoData.coverUrl | squareUrls" alt />
      </div>
      <div class="textarea">
        <el-input
          maxlength="500"
          show-word-limit
          v-model="data"
          type="textarea"
          ref="commentBox"
          :placeholder="userInfoData.name ? userInfoData.name + '：你想说些什么？' : userName + '你想对这篇文章说些什么？'"
        ></el-input>
      </div>
      <div class="btn">
        <el-button type="small" @click="_sendCommentData()">发送</el-button>
      </div>
    </div>
    <div v-else class="no-log">
      <span>你还未登录，只有登录之后才能对这篇文章提交评论！</span>
    </div>
  </div>
</template>
<script>
import { mapState } from "Vuex";
export default {
  data() {
    return {
      data: ""
    };
  },
  computed: {
    ...mapState("user", ["userInfoData"])
  },
  methods: {
    _sendCommentData() {
      if (this.data) {
        this.$emit("sendCommentData", this.data);
      } else {
        alert("你没有输入任何的内容！");
      }
    }
  }
};
</script>
<style lang="sass" scoped>
@import "@/assets/default.sass"
.send-message
  margin-top: 10px
  width: 100%
  background-color: #fff
  padding: 20px
  border-bottom: 1px solid #eee
  .has-loging
    width: 100%
    padding: 20px 0
    @include flex(space-between,center)
    .user-cover
      flex: 0 0 32px
      height: 32px
      overflow: hidden
      border-radius: 5px
      @include flex(center,center)
      >img
        width: 100%
        height: auto
    .textarea
      flex: 1
      padding: 0 2%
  .no-log
    width: 100%
    height: 134px
    @include flex(center,center)
</style>